#include "barrier.h"
#include<QTimer>
#include <QGraphicsScene>

const int speed = 200;
barrier::barrier(const QPixmap&pixmap,qreal barrier_x,qreal barrier_y,QObject* parent)
    :QObject(parent),QGraphicsPixmapItem(pixmap){
    setPos(barrier_x,barrier_y);//设置初始位置
    barriermove = new QPropertyAnimation(this, "pos");

    barriermove->setStartValue(QPointF(barrier_x, barrier_y));
    barriermove->setEndValue(QPointF(-50, barrier_y));
    barriermove->setDuration((barrier_x + 50)* 1000/speed);
    barriermove->start();
    connect(barriermove, &QPropertyAnimation::finished, this, [=]()
            {
                this->scene()->removeItem(this);
                this->deleteLater();
            });
}

void barrier::setPos1(const QPointF &pos)
{
    m_pos = pos;
    this->setPos(m_pos);
}




